#define SDHC_INFO *(unsigned long *)(0x0C003FF8)

#define globalBlockSizeHide *((volatile unsigned int*)(0x0C004000-0x4))

#define APP_BASE (2048+1025+1+16)

#define CopyMMCtoMem(z,a,b,c,e) (((unsigned char(*)(int, unsigned int, unsigned short, unsigned int*, unsigned char)) \
(*((unsigned int *)0x0C004008)))(z,a,b,c,e))

#define JumpApp (((void (*)(void)) (0x50000000))())

typedef void (*jump)(void);

#define UART_STATUS *((volatile unsigned int*)(0x7F005010))
#define UART_TX *((volatile unsigned int*)(0x7F005020))

void putString(char *s);

int main() 
{
    unsigned char res;

    char d1[] = "\r\nHello\r\n";
    char d2[] = "\r\nCopy OK!\r\n";
    char d3[] = "\r\nCopy Error!\r\n";

    putString(d1);

    res = CopyMMCtoMem( 1, globalBlockSizeHide - APP_BASE, 1024, (unsigned int*)0x50000000, 0);
    if (res)
    {
        putString(d2);
    }
    else
    {
        putString(d3);
        while(1);
    }
    
    JumpApp;
    while(1);
}

void putc(unsigned char data)
{
    UART_TX = data;
    while(!(UART_STATUS & 0x04));
}

void putString(char *s)
{
    while(*s != '\0')
    {
        putc(*s);
        s++;
    }
}
